package org.nobody.mallb2c.mallorder.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author 3489309323@qq.com
 * @create 2020-09-21-20:42
 */
@Data
public class OrderConfirmVo {
  //收货地址 ums_receive_address
  List<MemberAddressVo> address;

  //所有选中的购物项
  List<OrderItemVo> items;

  //发票...

  //优惠券信息
  Integer integration; //积分信息

  Map<Long,Boolean> stocks;

  //BigDecimal total; //订单总额
  public BigDecimal getTotal(){
    BigDecimal sum = new BigDecimal("0");
    if (items != null && items.size() > 0) {
      for (OrderItemVo item : items) {
        BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
        sum = sum.add(multiply);
      }
    }
    return sum;
  }

  public Integer getCount(){
    Integer i = 0;
    if (items != null) {
      for (OrderItemVo item : items) {
        i += item.getCount();
      }
    }
    return i;
  }

  //BigDecimal payPrice; //应付价格
  public BigDecimal getPayPrice(){
    //todo 应该减去优惠的
    return getTotal();
  }

  //防重令牌 防止订单重复提交
  String orderToken;
}
